function residual = static_resid(T, y, x, params, T_flag)
% function residual = static_resid(T, y, x, params, T_flag)
%
% File created by Dynare Preprocessor from .mod file
%
% Inputs:
%   T         [#temp variables by 1]  double   vector of temporary terms to be filled by function
%   y         [M_.endo_nbr by 1]      double   vector of endogenous variables in declaration order
%   x         [M_.exo_nbr by 1]       double   vector of exogenous variables in declaration order
%   params    [M_.param_nbr by 1]     double   vector of parameter values in declaration order
%                                              to evaluate the model
%   T_flag    boolean                 boolean  flag saying whether or not to calculate temporary terms
%
% Output:
%   residual
%

if T_flag
    T = model_htm.static_resid_tt(T, y, x, params);
end
residual = zeros(36, 1);
lhs = params(1)*y(11);
rhs = params(4)*(1-params(3))*y(9)+y(15)*params(3)*T(1)*(-params(13))*(1-T(1))+(params(1)-params(4)*(1-params(3)))*y(20);
residual(1) = lhs - rhs;
lhs = (1-params(1))*y(12);
rhs = (1-params(3))*(1-params(4))*y(10)+y(15)*T(1)*params(3)*params(13)*(1-T(1))+y(20)*params(3)*(1-T(1));
residual(2) = lhs - rhs;
lhs = params(11)*y(13);
rhs = y(13)*params(11)*params(9)+(1-params(11))*(1-params(11)*params(9))*(y(20)*params(7)+params(8)*y(11)-y(15)*(1-T(1)));
residual(3) = lhs - rhs;
lhs = params(12)*y(14);
rhs = y(14)*params(9)*params(12)+(1-params(12))*(1-params(9)*params(12))*(y(20)*params(7)+params(8)*y(12)+T(1)*y(15));
residual(4) = lhs - rhs;
residual(5) = params(10)*y(27)-params(14)*y(19);
residual(6) = y(29);
residual(7) = y(30);
lhs = y(31);
rhs = T(2)*(y(33)-y(27));
residual(8) = lhs - rhs;
lhs = y(20)*params(7);
rhs = y(31)+y(20)*params(7)-T(3)*(y(19)-y(27))-y(29)-y(30);
residual(9) = lhs - rhs;
lhs = y(27);
rhs = T(1)*y(13)+(1-T(1))*y(14);
residual(10) = lhs - rhs;
lhs = y(18);
rhs = params(1)*y(13)+(1-params(1))*y(14);
residual(11) = lhs - rhs;
lhs = y(16);
rhs = params(1)*y(11)+(1-params(1))*y(12);
residual(12) = lhs - rhs;
lhs = y(17);
rhs = params(4)*y(9)+(1-params(4))*y(10);
residual(13) = lhs - rhs;
lhs = y(15);
rhs = y(15)+y(13)-y(14);
residual(14) = lhs - rhs;
lhs = y(2);
rhs = y(2)*params(5)+params(23)*x(1);
residual(15) = lhs - rhs;
lhs = y(3);
rhs = y(3)*params(6)+params(24)*x(2);
residual(16) = lhs - rhs;
lhs = y(9);
rhs = y(2)*0.16;
residual(17) = lhs - rhs;
lhs = y(10);
rhs = y(3)*0.16;
residual(18) = lhs - rhs;
lhs = y(33);
rhs = params(17)*y(32)+params(18)*y(34);
residual(19) = lhs - rhs;
lhs = y(32);
rhs = y(32)*T(4)+(1-params(3))*(y(34)-y(33));
residual(20) = lhs - rhs;
lhs = y(34);
rhs = params(4)*y(35)+(1-params(4))*y(36);
residual(21) = lhs - rhs;
lhs = y(35);
rhs = y(27);
residual(22) = lhs - rhs;
lhs = y(36);
rhs = y(27);
residual(23) = lhs - rhs;
lhs = y(1);
rhs = y(2)+y(3);
residual(24) = lhs - rhs;
residual(25) = y(14);
lhs = y(21);
rhs = y(15)+y(22)/T(1);
residual(26) = lhs - rhs;
lhs = y(23);
rhs = y(20)+y(17);
residual(27) = lhs - rhs;
lhs = y(24);
rhs = y(19)-(T(1)*y(13)+(1-T(1))*y(14));
residual(28) = lhs - rhs;
lhs = y(25);
rhs = params(3)*y(20);
residual(29) = lhs - rhs;
lhs = y(26);
rhs = (1-params(3))*y(17);
residual(30) = lhs - rhs;
lhs = y(5);
rhs = y(26)*(1-params(3))*params(4)/params(1);
residual(31) = lhs - rhs;
lhs = y(6);
rhs = y(26)*(1-params(3))*(1-params(4))/(1-params(1));
residual(32) = lhs - rhs;
lhs = y(28);
rhs = y(19)*12;
residual(33) = lhs - rhs;
lhs = y(7);
rhs = (-(y(20)*params(7)+params(8)*y(11)-y(15)*(1-T(1))));
residual(34) = lhs - rhs;
lhs = y(8);
rhs = (-(y(20)*params(7)+params(8)*y(12)+T(1)*y(15)));
residual(35) = lhs - rhs;
lhs = y(4);
rhs = params(1)*y(7)+(1-params(1))*y(8);
residual(36) = lhs - rhs;
if ~isreal(residual)
  residual = real(residual)+imag(residual).^2;
end
end
